using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Colorprj.Masters;
using System.Data.Common;

namespace Colorprj.Login
{
    class LoginManager
    {

        public LoginUser GetUser(string  userName)
        {
            bool result = false;
            if (string.IsNullOrEmpty(userName)) {
                throw new Exception("UserName Can not Be Null"); 
            
            }
            // Create the Database object, using the default database service. The
            // default database service is determined through configuration.
            Database db = DatabaseFactory.CreateDatabase();
            LoginUser lu = new LoginUser(); 
            // Two operations, one to credit an account, and one to debit another
            // account.
            string sqlCommand = "SelUser";
            DbCommand creditCommand = db.GetStoredProcCommand(sqlCommand);
            db.AddInParameter(creditCommand, "UserName", DbType.String, userName);
            DataSet UserDataSet = db.ExecuteDataSet(creditCommand);
            if (UserDataSet.Tables[0].Rows.Count == 0) throw new Exception("UserName not Found"); 
            lu.PassWord = UserDataSet.Tables[0].Rows[0]["UserPassword"].ToString(); ;
            return lu;
        }
        public void setCompany()
        {
            bool result = false;
           
            // Create the Database object, using the default database service. The
            // default database service is determined through configuration.
            Database db = DatabaseFactory.CreateDatabase();
            LoginUser lu = new LoginUser();
            // Two operations, one to credit an account, and one to debit another
            // account.
            string sqlCommand = "SelControl";
            DbCommand creditCommand = db.GetStoredProcCommand(sqlCommand);
           
            DataSet UserDataSet = db.ExecuteDataSet(creditCommand);
            if (UserDataSet.Tables[0].Rows.Count == 0) throw new Exception("UserName not Found");
            Globalclass.CompanyName = UserDataSet.Tables[0].Rows[0]["cName"].ToString();
            Globalclass.Address1 = UserDataSet.Tables[0].Rows[0]["add1"].ToString();
            Globalclass.Address2 = UserDataSet.Tables[0].Rows[0]["add2"].ToString();
            Globalclass.PhoneNo = UserDataSet.Tables[0].Rows[0]["phone"].ToString();
            Globalclass.Email = UserDataSet.Tables[0].Rows[0]["email"].ToString();
            Globalclass.TinNo = UserDataSet.Tables[0].Rows[0]["TinNo"].ToString();
            Globalclass.CstNo = UserDataSet.Tables[0].Rows[0]["CSTNO"].ToString();
            Globalclass.DbName = UserDataSet.Tables[0].Rows[0]["DbName"].ToString();
            Globalclass.DsnName = UserDataSet.Tables[0].Rows[0]["DsnName"].ToString(); 
        }


    }
}
